#ifndef DEVICEPARAMETERWIDGET_H
#define DEVICEPARAMETERWIDGET_H

#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QMap>
#include <QPushButton>
#include <QString>
#include <QWidget>

class DeviceParameterWidget : public QGroupBox
{
    Q_OBJECT

public:
    explicit DeviceParameterWidget(const QString& deviceName, const QVariantMap& configMap,
                                   QWidget* parent = nullptr);
    ~DeviceParameterWidget();

    // 获取当前组件的配置参数
    QVariantMap getConfigValues() const;

    // 更新配置值
    void updateConfigValues(const QVariantMap& configMap);

    // 获取设备名称
    QString getDeviceName() const { return m_deviceName; }

signals:
    void parametersChanged(const QString& deviceName, const QVariantMap& configValues);

private slots:
    void onSaveButtonClicked();

private:
    void showEvent(QShowEvent* event) override;
    void setupUI();
    void connectSignals();
    QAbstractSpinBox* createComponents(QVariant value);

private:
    QString m_deviceName;
    QVariantMap m_configMap;

    QGridLayout* m_gridLayout;
    QMap<QString, QWidget*> m_spinBoxMap;  // 配置键对应的输入框
    QPushButton* m_saveButton;
};

#endif  // DEVICEPARAMETERWIDGET_H